package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.PermissionsPostBO;
import com.cskaoyan.bean.bo.RoleBO;
import com.cskaoyan.bean.bo.RoleCreateBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.RolePO;
import com.cskaoyan.bean.vo.RoleVO;
import com.cskaoyan.bean.vo.TVO;
import com.cskaoyan.service.AdminService;
import com.cskaoyan.service.RoleService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/role")
public class RoleController {
    @Autowired
    AdminService adminService;
    @Autowired
    RoleService roleService;

    @RequestMapping("options")
    public BaseRespVo options() {
        TVO<RoleVO> roles = adminService.queryAllRole();
        return BaseRespVo.ok(roles);
    }

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam,String name) {
        TVO<RolePO> roles = roleService.queryAllRole(baseParam,name);
        return BaseRespVo.ok(roles);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody RoleBO roleBO) {
       return roleService.update(roleBO);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody RoleBO roleBO) {
        return roleService.delete(roleBO);
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody RoleCreateBO createBO) {
        return roleService.create(createBO);
    }

    @GetMapping("permissions")
    public BaseRespVo permissionsGet(Integer roleId) {
        return roleService.permissions(roleId);
    }
    @PostMapping("permissions")
    public BaseRespVo permissionsPost(@RequestBody PermissionsPostBO permissionsPostBO) {
        return roleService.permissionsPost(permissionsPostBO);
    }
}
